package com.flyoil.petromp.mvp_m.SearchCertainModel;

import com.flyoil.petromp.apiservice.OnObserverRetrofitResetCallBack;
import com.flyoil.petromp.base.BaseEntity;
import com.flyoil.petromp.entity.entity_course_list.CourseCertainEntity;
import com.flyoil.petromp.entity.entity_course_list.ServiceDemandListEntity;
import com.flyoil.petromp.entity.entity_course_list.ServiceExamineListEntity;
import com.flyoil.petromp.entity.entity_order.MapListEntity;
import com.flyoil.petromp.mvp_p.Listener.OnPresenterListener;
import com.flyoil.petromp.utils.OrderUtl.OrderListUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by songzhiyin on 2017/11/1.
 * 服务验收单列表单据搜索输入数据界面的数据处理类
 */

public class SearchServiceExamineModel implements SearchBaseModel {


    @Override
    public void loadNetworkData(Map<String, Object> map, final OnPresenterListener listener) {
        httpModel.getCourseServiceExamineList(map, new OnObserverRetrofitResetCallBack<BaseEntity>() {
            @Override
            public void onSuccess(BaseEntity model) {
                super.onSuccess(model);
                ServiceExamineListEntity serviceExamineListEntity = null;
                if (model instanceof ServiceExamineListEntity) {
                    serviceExamineListEntity = (ServiceExamineListEntity) model;
                }
                if (serviceExamineListEntity != null && serviceExamineListEntity.getData() != null && serviceExamineListEntity.getData().getList() != null) {
                    List<CourseCertainEntity> courseCertainEntities = new ArrayList<>();
                    for (int i = 0; i < serviceExamineListEntity.getData().getList().size(); i++) {
                        ServiceExamineListEntity.DataBean.ListBean data = serviceExamineListEntity.getData().getList().get(i);
                        CourseCertainEntity item = new CourseCertainEntity();
                        item.setId(data.getId());
                        item.setTitle(data.getServiceRequirementName());
                        item.setNumber(data.getServiceOrderSn());
                        item.setTime(data.getCreatedTimeLabel());
                        item.setType(OrderListUtil.SERVICE_EXAMINE);
                        courseCertainEntities.add(item);
                    }
                    listener.onsucced(courseCertainEntities);
                } else {
                    listener.onsucced(null);
                }
            }

            @Override
            public void onFailure(String msg) {
                listener.onsucced(null);
            }
        });
    }


    @Override
    public void loadUiData(OnPresenterListener listener) {
        List<MapListEntity> data_hint = new ArrayList<>();
        data_hint.add(new MapListEntity("订单编号", "请输入订单编号"));
        data_hint.add(new MapListEntity("供应商", "请输入供应商"));
        listener.onsucced(data_hint);
    }
}
